/*team-personnel*/
/*nav-program*/
var ProgramTable1 = [
    [ "接受工程检查评估", "项目办", "工程管理部","检查评估","进行中", "中", "严重" ,"2017-01-03","2017-01-12","延误","2017-01-05"]
];
var ProgramTable2 = [
    [ "admin 于 2016-12-22 执行了 控制账户-232132132", "2.0小时", "进行中","2017-01-05" ]
];
function fnFormatDetails ( oTable, nTr )
{
    var aData = oTable.fnGetData( nTr );
    var sOut = '<table cellpadding="5" cellspacing="0" border="0" style="padding-left:50px;">';
    sOut += '<tr><td>Rendering engine:</td><td>'+aData[1]+' '+aData[4]+'</td></tr>';
    sOut += '<tr><td>Link to source:</td><td>Could provide a link here</td></tr>';
    sOut += '<tr><td>Extra info:</td><td>And any further details here (img etc)</td></tr>';
    sOut += '</table>';

    return sOut;
}

$(document).ready(function() {

    /*team-personnel*/
    var Projectstaff = $('#dynamic-table').dataTable( {
        "aaSorting": [[ 0, "desc" ]],
        "iDisplayLength": 5,
        "aLengthMenu": [5, 10, 25, 50],
        //"aaData": dataSet1,
        //"aoColumns": [
        //    { "sTitle": "成员编号" },
        //    { "sTitle": "成员姓名" },
        //    { "sTitle": "工号" },
        //    { "sTitle": "岗位名称" },
        //    { "sTitle": "所属部门" },
        //    { "sTitle": "所属公司" }
        //]
    } );
    /*collisionList*/
    $('#collisionList-table').dataTable( {
        "aaSorting": [[ 0, "asc" ]],
        "iDisplayLength": 10,
        "aLengthMenu": [5, 10, 25, 50],
    } );
    /*p-task*/
    $('#MyTaskTable-1').dataTable( {
        "aaSorting": [[ 6, "desc" ]],
        "iDisplayLength": 5,
        "aLengthMenu": [5, 10, 25, 50],
       // "aaData": MyTaskTable1,
        "aoColumns": [
            { "sTitle": "任务名称" },
            { "sTitle": "执行" },
            { "sTitle": "发起" },
            { "sTitle": "类型" },
            { "sTitle": "状态" },
            { "sTitle": "优先级" },
         /*   { "sTitle": "严重度" },*/
            { "sTitle": "开始日期" },
            { "sTitle": "结束日期" },
            { "sTitle": "父级" },
            { "sTitle": "操作" }
        ]
    } );
   
    /*nav-program*/
    $('#pTaskTable-1').dataTable( {
        "aaSorting": [[ 0, "desc" ]],
        "iDisplayLength": 5,
        "aLengthMenu": [5, 10, 25, 50],
        //"aaData": ProgramTable1,
        "aoColumns": [
            { "sTitle": "任务名称" },
            { "sTitle": "执行" },
            { "sTitle": "发起" },
            { "sTitle": "类型" },
            { "sTitle": "状态" },
            { "sTitle": "优先级" },
            { "sTitle": "严重度" },
            { "sTitle": "开始日期" },
            { "sTitle": "结束日期" }
        ]
    } );
    $('#pTaskTable-2').dataTable( {
        "aaSorting": [[ 2, "desc" ]],
        "iDisplayLength": 5,
        "aLengthMenu": [5, 10, 25, 50],
       // "aaData": ProgramTable2,
        "aoColumns": [
            { "sTitle": "动态" },
            { "sTitle": "IP" },
            { "sTitle": "更新于" }
        ]
    } );
    /*p-program*/
    $('#mProgramTable-1,#mProgramTable-2,#mProgramTable-3').dataTable( {
        "aaSorting": [[ 7, "desc" ]],
        "iDisplayLength": 5,
        "aLengthMenu": [10],
        "aoColumns": [
            { "sTitle": "项目代码" },
            { "sTitle": "项目名称" },
            { "sTitle": "开始日期" },
            { "sTitle": "截止日期" },
            { "sTitle": "负责人" },
            { "sTitle": "项目进度" },
            { "sTitle": "更新时间" },
            { "sTitle": "操作" }
        ]
    } );


    $('#dynamic-table tbody').on( 'click', 'tr', function () {
        if ( $(this).hasClass('selected') ) {
            $(this).removeClass('selected');
        }
        else {
            Projectstaff.$('tr.selected').removeClass('selected');
            $(this).addClass('selected');
        }
    } );

    //$('#advtable-delete').click( function () {
    //    Projectstaff.row('.selected').remove().draw( false );
    //} );



    /*  Insert a 'details' column to the table  */
    var nCloneTh = document.createElement( 'th' );
    var nCloneTd = document.createElement( 'td' );
    nCloneTd.innerHTML = '<img src="">';
    nCloneTd.className = "center";

    $('#hidden-table-info thead tr').each( function () {
        this.insertBefore( nCloneTh, this.childNodes[0] );
    } );

    $('#hidden-table-info tbody tr').each( function () {
        this.insertBefore(  nCloneTd.cloneNode( true ), this.childNodes[0] );
    } );

    /*
     * Initialse DataTables, with no sorting on the 'details' column
     */
    var oTable = $('#hidden-table-info').dataTable( {
        "aoColumnDefs": [
            { "bSortable": false, "aTargets": [ 0 ] }
        ],
        "aaSorting": [[1, 'asc']]
    });

    /* Add event listener for opening and closing details
     * Note that the indicator for showing which row is open is not controlled by DataTables,
     * rather it is done here
     */
    $(document).on('click','#hidden-table-info tbody td img',function () {
        var nTr = $(this).parents('tr')[0];
        if ( oTable.fnIsOpen(nTr) )
        {
            /* This row is already open - close it */
            this.src = "";
            oTable.fnClose( nTr );
        }
        else
        {
            /* Open this row */
            this.src = "../public/images/details_close.png";
            oTable.fnOpen( nTr, fnFormatDetails(oTable, nTr), 'details' );
        }
    } );
} );